﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using imaginecup.information;
using imaginecup.objectManager;
using Imaginecup.gameState.malaria.componentInit;
using Microsoft.Xna.Framework;

namespace Imaginecup.gameState.malaria.component.entity.item
{
    public abstract class BaseCoolTimeItemEntityComponent : BaseItemEntityComponent
    {

        public enum CoolState { Using, Delay, Stop , None }
        public BaseCoolTimeItemEntityComponent(GObjectID a_GID, ObjectManager objMan, SComponentTypeID componentTypeID)
            : base(a_GID, objMan, componentTypeID)
        {

            m_State = CoolState.Delay;
            m_CoolCalculateTime = m_CoolTime;

            m_bEnd = false;
        }

        protected CoolState m_State;

        protected double m_CoolTime;

        protected double m_CoolCalculateTime;

        protected bool m_bEnd;


        public override void Update(GameTime gameTime)
        {

            if (m_State == CoolState.Delay)
            {
                m_CoolCalculateTime -= gameTime.ElapsedGameTime.TotalSeconds;

                if (m_CoolCalculateTime < 0)
                {
                    m_CoolCalculateTime = 0;
                    m_State = CoolState.None;
                }
            }

            //else if (m_State == CoolState.Using)
            //{
            //    m_UsingCalculateTime -= gameTime.ElapsedGameTime.TotalSeconds;

            //    if (m_UsingCalculateTime < 0)
            //    {
            //        m_UsingCalculateTime = 0;
            //        SetClear();
            //        m_CoolCalculateTime = m_CoolTime;
            //        m_State = CoolState.Delay;
            //        m_bEnd = true;
            //        m_bSelectItem = false;
            //    }
            //}
            base.Update(gameTime);
        }
     
        protected abstract void SetClear();

        public override void DisableItem()
        {
            SetClear();
            if( m_State == CoolState.Using )
                m_State = CoolState.Stop;
            base.DisableItem();
        }

        public override double GetCoolTimeRate()
        {
            return m_CoolCalculateTime / m_CoolTime;
        }

        public override bool IsUseAble()
        {
            if (m_State == CoolState.Using)
            {
                return true;
            }
            else if( m_State == CoolState.None )
            {//정지되어있다가 다시 계산.
                m_State = CoolState.Using;
                m_bEnd = false;
            }
            else if( m_State == CoolState.Stop )
            {
                m_State = CoolState.Using;
                return true;
            }
            return false;
        }
                 

        public override bool IsStateEnd()
        {
            return m_bEnd;
        }

        public override bool IsSelectAble()
        {
            if (m_State != CoolState.Delay)
                return true;
            return false;
        }
    }
}
